package com.example.demoexternalusagediceroller;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class DiceRollerReceiver extends BroadcastReceiver {

	public static CallbackGetGamesResponse callbackGetGamesResponse;
	public static CallbackGetPresetsResponse callbackGetPresetsResponse;

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.d("TEST SERVICE", "result intent action=" + intent.getAction());

		if (intent.getAction().equals("org.amphiprion.diceroller.GetGamesResponse")) {
			String[] names = intent.getStringArrayExtra("GAME_NAMES");
			String[] paths = intent.getStringArrayExtra("GAME_PATHS");
			// for (int i = 0; i < names.length; i++) {
			// Log.d("TEST SERVICE", "      game=" + names[i] + "  path=" + paths[i]);
			//
			// }
			if (callbackGetGamesResponse != null) {
				callbackGetGamesResponse.onGamesResponse(names, paths);
			}
		} else if (intent.getAction().equals("org.amphiprion.diceroller.GetPresetsResponse")) {
			String[] ids = intent.getStringArrayExtra("PRESET_IDS");
			String[] names = intent.getStringArrayExtra("PRESET_NAMES");
			// for (int i = 0; i < names.length; i++) {
			// Log.d("TEST SERVICE", "      id=" + ids[i] + "  name=" + names[i]);
			//
			// }
			if (callbackGetPresetsResponse != null) {
				callbackGetPresetsResponse.onPresetsResponse(ids, names);
			}
		}
	}

	public interface CallbackGetGamesResponse {
		void onGamesResponse(String[] names, String[] paths);
	}

	public interface CallbackGetPresetsResponse {
		void onPresetsResponse(String[] ids, String[] names);
	}

}
